package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.base.shiro.annotion.Permission;
import cn.stylefeng.guns.sys.core.shiro.ShiroKit;
import cn.stylefeng.guns.sys.modular.system.entity.SysDeptPositions;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.model.params.SysDeptPositionsParam;
import cn.stylefeng.guns.sys.modular.system.service.SysDeptPositionsService;
import cn.stylefeng.guns.sys.modular.system.warpper.DeptWrapper;
import cn.stylefeng.guns.sys.modular.system.warpper.UserWrapper;
import cn.stylefeng.guns.sys.modular.system.warpper.sysDeptPositionsWrapper;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.datascope.DataScope;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.Wrapper;
import java.util.Map;


/**
 * 部门岗位关系表控制器
 *
 * @author 
 * @Date 2024-01-10 14:38:27
 */
@Controller
@RequestMapping("/sysDeptPositions")
public class SysDeptPositionsController extends  BaseController  {

    private String PREFIX = "/modular/system/sysDeptPositions";

    @Autowired
    private SysDeptPositionsService sysDeptPositionsService;

    @Autowired
    private UserService userService;

    /**
     * 跳转到主页面
     *
     * @author 
     * @Date 2024-01-10
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/sysDeptPositions.html";
    }

    /**
     * 新增页面
     *
     * @author 
     * @Date 2024-01-10
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/sysDeptPositions_add.html";
    }

    /**
     * 编辑页面
     *
     * @author 
     * @Date 2024-01-10
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/sysDeptPositions_edit.html";
    }

    /**
     * 新增接口
     *
     * @author 
     * @Date 2024-01-10
     */

    @RequestMapping("/toPostadd")
    public String toAssignMaterial() {
        return PREFIX + "/Postadd.html";
    }
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(SysDeptPositionsParam sysDeptPositionsParam) {
        User user = userService.getcurrentUser();
        sysDeptPositionsParam.setDeliverId(user.getDeliverId());
        this.sysDeptPositionsService.add(sysDeptPositionsParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author 
     * @Date 2024-01-10
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(SysDeptPositionsParam sysDeptPositionsParam) {
        this.sysDeptPositionsService.update(sysDeptPositionsParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author 
     * @Date 2024-01-10
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(SysDeptPositionsParam sysDeptPositionsParam) {
        this.sysDeptPositionsService.delete(sysDeptPositionsParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author 
     * @Date 2024-01-10
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(SysDeptPositionsParam sysDeptPositionsParam) {
        SysDeptPositions detail = this.sysDeptPositionsService.getById(sysDeptPositionsParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author 
     * @Date 2024-01-10
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam(value = "condition", required = false) String condition, //选择的部门名称
                       @RequestParam(value = "deptId", required = false) Long deptId) {  //选择的部门id

        Long DeliverId = userService.getDeliverId();
        Page<Map<String, Object>> list = this.sysDeptPositionsService.list(condition, deptId,DeliverId);
        Page<Map<String, Object>> wrap = new sysDeptPositionsWrapper(list).wrap();
        return LayuiPageFactory.createPageInfo(wrap);

    }

}


